<?php get_header();

$tagname = get_query_var('tag');
$name =  single_tag_title("", false); ?>

 <script type="text/javascript">
    $('.header').addClass('contact');
</script>
<script src="<?php echo bloginfo('template_url'); ?>/js/jquery-migrate-1.2.1.js"></script>
        <div class="row">
                <div class="col-12 header-description">
                    <div class="title step">
                        <div class="line_1"><?php echo $name; ?></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Content -->
    <div class="container">
      <div class="row">
         <?php
            wp_reset_query();
            $posts_per_page = 6;
            $page = (get_query_var('page')) ? get_query_var('page') : 1;
            query_posts(array('tag' => $tagname,'posts_per_page'=>$posts_per_page,'page' => $page, 'offset' => $posts_per_page*($page-1)));
            while (have_posts()): the_post();
            if (has_post_thumbnail()) {
               $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
               $url_to_image = $large_image_url[0];
            } else {
             $url_to_image = bloginfo('template_url').'/img/no-image-blog-one.png';
            }
             ?>
        <div class="col-lg-4 col-sm-6 col-12">
          <div class="news-item">
                    <div class="news-thumb">
                        <img src="<?php echo $url_to_image ?>" />
                    </div>
                    <div class="news-date" style="display:none;"><?php the_time('d.m.Y') ?></div>
                    <div class="news-title"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></div>
                    <div class="news-description">
                        <?php the_content(''); ?> 
                    </div>
                    <div class="read-more">
                        <a href="<?php the_permalink() ?>">>> Chi tiết</a>
                    </div>

                </div>
        </div>
        <?php endwhile; ?>
        <script type="text/javascript">
        $('.ratingblock').each(function(){
          $(this).insertAfter($(this).parent());
        });
        </script>
        <?php
              global $wp_query;
              $pagination = paginate_links( array(
                  'current' =>  max( 1,get_query_var('page')),
                  'total' => $wp_query->max_num_pages,
                  'type' => 'array',
                  'next_text' => '»',
                  'prev_text' => '«'
              ) );
              ?>
              <?php if(isset($pagination)){ 
              $pagination = str_replace("href=''", "href='".get_category_link('')."?page=1'", $pagination);
              $pagination = str_replace('href=""', 'href="'.get_category_link('').'?page=1"', $pagination);
              ?>
              <div class="paginations no-float col-sm-offset-4 col-lg-offset-4 col-lg-4 col-sm-4">
                <ul>
                  <?php $i=0; foreach($pagination as $page){ ?>
                    <li>
                        <?php echo $page; ?>
                    </li>
                  <?php } ?>
                </ul>
              </div>
              <?php } ?>
      </div>
    </div>
    <!-- End Content -->
    
<?php get_footer() ?>